<!DOCTYPE html>
<meta charset="utf-8" />

<link rel="stylesheet" href="ace_v1.3/assets/css/ui.jqgrid.css" />

<div class="search_panel">
<form id="searchForm" method="post" onsubmit="return pageSearch(this);">
	<div style="display: block;" class="widget-body ">
		<div class="widget-main">
			<div class="rowt">
				<div class="col-sm-12">
					<div>
						<div class="search_elm" style="margin-left: 0px;width: 300px;">
							 <label class="label_search">合作商名称:</label>
							<div class="search_input">
		<!-- 					<input id="search_agentName" type="text" name="agentName" placeholder="请输入合作商名称"> -->
							 <select 
								 rel="obj.options"
								 location="mpamng/selectoption/agentName.do" 
								 name="agentName" 
								 id="search_agentName" 
								 data-placeholder="请选择合作商名称" style="width: 200px;vertical-align:middle;">
								<option value='' >----请选择----</option>
							 </select>
							</div> 
						</div>
						
						<div class="search_elm" style="margin-left: 0px">
							<label class="label_search">订单号:</label>
							<div class="search_input">
								<input id="prdOrdNo" type="text" name="orderNo" placeholder="请输入交易订单号">
							</div>
						</div>
						<div class="search_elm" style="margin-left: 0px">
							<label class="label_search">商户编号:</label>
							<div class="search_input">
								<input id="custId" type="text" name="custId" placeholder="请输入商户编号">
							</div>
						</div>
						<div class="search_elm" style="margin-left: 0px">
							<label class="label_search">商户名称:</label>
							<div class="search_input">
								<input id="custName" type="text" name="custName" placeholder="请输入商户名称">
							</div>
						</div>
						<div class="search_elm" style="margin-left: 0px">
							<label class="label_search">结算批次号:</label>
							<div class="search_input">
								<input id="batchNo" type="text" name="batchNo" placeholder="请输入结算批次号">
							</div>
						</div>
						<div class="search_elm" style="margin-left: 0px;width: 300px;">
							 <label class="label_search">结算状态:</label>
							<div class="search_input">
							 <select 
								rel="obj.SHAR_STATUS"
						 			location="local" 
									name="sharStatus" 
						 			id="sharStatus" 
								 data-placeholder="请选择结算状态" style="width: 150px;vertical-align:middle;">
								<option value='' >----请选择----</option>
							 </select>
							</div> 
						</div>
						<div class="search_elm" style="margin-left: 0px;margin-right: 15px;width: 280px;">
						    <label class="label_search">分润日期:</label>
							<div class="input-group">
								<input type="text" class="form-control date-picker" id="startTime" name="startTime" placeholder="起始日期"  data-date-format="yyyy-mm-dd"/>
								<span class="input-group-addon">
									<i class="fa fa-exchange"></i>
								</span>
								<input type="text" class="form-control  date-picker" id="endTime" name="endTime" placeholder="结束日期" data-date-format="yyyy-mm-dd"/>
							</div>

							<!-- /section:plugins/date-time.datepicker -->
						</div>
						<!-- <div style="float: left;width: 100px">
							<label class="">一级合作商： </label>
							<div>
								<label>
									<input id="agentDgr1" name="agentDgr1" type="checkbox" value="0"/>
								</label>
							</div>
						</div>
						<div style="float: left;width: 100px">
							<label class="">二级合作商： </label>
							<div>
								<label>
									<input id="agentDgr2" name="agentDgr2" type="checkbox" value="0"/>
								</label>
							</div>
						</div>
						<div style="float: left;width: 100px">
							<label class="">三级合作商： </label>
							<div>
								<label>
									<input id="agentDgr3" name="agentDgr3" type="checkbox" value="0"/>
								</label>
							</div>
						</div> -->
						<div class="search_elm" style="margin-right: 5px;">
							<button class="btn btn-small btn_search" type="submit" title="搜索" onclick="searchCount();"> 搜索 </button>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
	</form>
</div>
<div class="row">
		<div style="display: block;" class="col-xs-12"  id="total">
		</div>
</div>
	<div class="rowt">
		<div class="col-xs-12">
			<table id="grid-table"></table>
			<div id="grid-pager"></div>
			<div style="margin-top: 10px">
				<span id="auth_btn">
					<!-- <a class="btn btn-small btn-success" onclick="reportData();"> 导出数据文件</a> -->
				</span> <span id="paging_bar" style="float: right"> </span>
			</div>

		</div>
	</div>

	<script type="text/javascript">
		var jqGrid;
		jQuery(function($) {
			var grid_selector = "#grid-table";
			var pager_selector = "#grid-pager";

			$(window).on(
					'resize.jqGrid',
					function() {
						$(grid_selector).jqGrid('setGridWidth',$(".page-content").width());
					})
			var parent_column = $(grid_selector).closest('[class*="col-"]');
			$(document).on(
					'settings.ace.jqGrid',
					function(ev, event_name, collapsed) {
						if (event_name === 'sidebar_collapsed'|| event_name === 'main_container_fixed') {
							setTimeout(function() {
								$(grid_selector).jqGrid('setGridWidth',parent_column.width());
							}, 0);
						}
					})
			jQuery(grid_selector).jqGrid({
				url : "mpamng/agent/queryCustProfit.do",
				datatype : "json",
				height : '100%',
				width : '100%',
				colNames : [ '商户编号','商户名称','合作商编号', '合作商名称','分润日期','交易类型','交易订单号','交易金额','分润比例(百分之)','分润金额(元)','结算状态','结算批次号'],
				colModel : [ {name : 'custId',			index : 'custId',			width : '100px',sortable:false}, 
				             {name : 'custName',    	index : 'custName',     	width : '150px' ,sortable:false},
				             {name : 'agentId',			index : 'agentId',			width : '150px',sortable:false},
				             {name : 'agentName',    	index : 'agentName',     	width : '200px' ,sortable:false},
				             {name : 'sharDate',     	index : 'sharDate',    		width : '80px' ,sortable:false },
				             {name : 'orderType',     	index : 'orderType',    	width : '80px' ,sortable:false,ditcKey:'PRDORDTYPE', formatter:gridFormatByDict },
				             {name : 'orderNo',     	index : 'orderNo',    	width : '130px' ,sortable:false},
				             {name : 'orderAmt',     	index : 'orderAmt',     	width : '100px' ,sortable:false},
				             {name : 'sharProfit',     	index : 'sharProfit',     	width : '130px' ,sortable:false},
				             {name : 'sharAmt',     	index : 'sharAmt',     		width : '100px' ,sortable:false},
				             {name : 'sharStatus',     	index : 'sharStatus',     		width : '100px' ,sortable:false,ditcKey:'SHAR_STATUS', formatter:gridFormatByDict},
				             {name : 'batchNo',     	index : 'batchNo',     		width : '130px' ,sortable:false}
				            ],
				viewrecords : true,
				rowNum : 10,
				rowList : [ 10, 20, 30 ],
				altRows : true,
				shrinkToFit:false,
				multiselect : true,//设置行可多选的 
				multiboxonly : true,//

				loadComplete : function() {
					var table = this;
					setTimeout(function() {
						//加载分页
						initPagingBar(grid_selector);
					}, 0);
				},
				beforeRequest : function() {//请求之前执行
					jqGrid = this;
				},
			});
			$(window).triggerHandler('resize.jqGrid');

			$(document).one('ajaxloadstart.page', function(e) {
				$(grid_selector).jqGrid('GridUnload');
				$('.ui-jqdialog').remove();
			});
			//定义按钮
			function optionEdit(cellvalue, options, rowObject) {
				var button = "<div class=\"hidden-sm hidden-xs btn-group\">";  //定义button
				button += "<button class='btn btn-xs btn-warning'  title='详细信息查看' onclick='profitSharingView(\""+rowObject["agentId"]+"\",\""+rowObject["sharDate"]+"\");'>详细</button>";
				button += "</div>";
				return button;
			}
			//定义表格列中金额转换 元转分
			function centYuan(cellvalue, options, rowObject) {
				return cent2Yuan(cellvalue);
			}
		});

		function profitSharingView(agentId,sharDate) {
			openDialog({
				dialogId : 'dlg-profitSharingDetail',
				title : '收益详情',
				pageUrl : 'mpamng/agent/queryProfitSharingDetailView.do',
				dataUrl : '',
				width : '90%',
				height:'80%',
				pageParam: {
					agentId : agentId,
					sharDate:sharDate
				},
				dataName : 'obj,map' //表单数据存储对象名称
			});
		}
		
		function reportData(){
			var agentNmae = $('#search_agentName').val();
			var startTime = $('#startTime').val();
			var endTime = $('endTime').val();
			var agentDgr1 = "";
			var agentDgr2 = "";
			var agentDgr3 = "";
			if($('#agentDgr1').is(':checked')) {
				agentDgr1 = $('#agentDgr1').val();
			}
			if($('#agentDgr2').is(':checked')) {
				agentDgr2 = $('#agentDgr2').val();
			}
			if($('#agentDgr3').is(':checked')) {
				agentDgr3 = $('#agentDgr3').val();
			}
			var querycon = {"server":"10","agentName":agentNmae,"startTime":startTime,"endTime":endTime
					,"agentDgr1":agentDgr1,"agentDgr2":agentDgr2,"agentDgr3":agentDgr3};
			report(querycon);
		}
		
		$(document).ready(function(){
			 searchCount();
		
		 });
		function searchCount(){
			
			var count="0";
			var fee="0";
			var html="";
			// $(document).ready(function(){
				 $.ajax({
						type : "post",
						url :"mpamng/agent/custProfitSum.do",
						data:$("#searchForm").serialize(),
						dataType : 'json',
						async:true,//为true，异步请求
						success : function(result) {
						if(result.rspcod==200){
							var obj = result.obj;
								html+="交易总额:["+obj['orderAmt']+"]元  |   "
								html+="&nbsp;&nbsp;&nbsp;&nbsp;";
								html+="交易总笔数:["+obj['cntNum']+"]笔";
								html+="&nbsp;&nbsp;&nbsp;&nbsp;";
								html+="分润总额:["+obj['sharAmt']+"]元";
								$("#total").html(html);
						}
					},
					error : function(XMLHttpRequest, textStatus) {
						msg.alert("错误", "错误代码：" + XMLHttpRequest.status + ",错误描述："+ textStatus, 'error');
					}
				});
			

		//});
			
		}
	</script>